<template>
  <view class="workbenchChild">
    <pit-header :title="title"></pit-header>
    <pit-news v-if="menuId==='1656909564945002496'" :newslist="newslist"></pit-news>
    <pit-notice v-else-if="menuId==='1656909810819297280'" :noticelist="noticelist"></pit-notice>
    <view class="video" v-else-if="menuId==='1754347667021459458'">
      <view v-for="(item,index) in videolist" :key="index" class="list-item">
        <img src="/static/home/workbench/quality_testing_empty.png" alt="空白文档" class="list-item-img"/>
        <text class="list-item-text">{{item}}</text>
      </view>
    </view>
    <view class="check" v-else-if="menuId==='1801533044718862337'">
      <view v-for="(item,index) in checklist" :key="index" class="list-item">
        <img src="/static/home/workbench/quality_testing_empty.png" alt="空白文档" class="list-item-img"/>
        <text class="list-item-text">{{item}}</text>
      </view>
    </view>
    <pit-meeting v-else-if="menuId==='1656918611253424128'" :meetlist="meetlist"></pit-meeting>
    <view class="safety" v-else-if="menuId==='1662350422957215744'">
      <view v-for="(item,index) in safetylist" :key="index" class="list-item">
        <img :src="item.img" alt="空白文档" class="list-item-img"/>
        <text class="list-item-text">{{item.title}}</text>
      </view>
    </view>
    <pit-quality v-else-if="menuId==='1656917648744542208'"></pit-quality>
    <view class="qualitycheck" v-else-if="menuId==='1747791302224297985'">
      <view v-for="(item,index) in qualitychecklist" :key="index" class="list-item">
        <img src="/static/home/workbench/quality_testing_empty.png" alt="空白文档" class="list-item-img"/>
        <text class="list-item-text">{{item}}</text>
      </view>
    </view>
    <pit-builder v-else-if="menuId==='1656918772415361024'" :buildlist="buildlist"></pit-builder>
    <pit-supervisiondiary v-else-if="menuId==='1681556169740386304'" :supervisiondiarylist="supervisiondiarylist"></pit-supervisiondiary>
    <pit-supervisionlog v-else-if="menuId==='1656918929982779392'" :supervisionloglist="supervisionloglist"></pit-supervisionlog>
    <pit-supervisionrecord v-else-if="menuId==='1703612152340373505'" :supervisionrecordlist="supervisionrecordlist"></pit-supervisionrecord>
    <pit-supervisorsite v-else-if="menuId==='1703612627680845826'" :supervisorsitelist="supervisorsitelist"></pit-supervisorsite>
    <pit-projectlog v-else-if="menuId==='1689091705713315842'" :projectloglist="projectloglist"></pit-projectlog>
    <pit-design v-else-if="menuId==='1681263417527844864'" :designlist="designlist"></pit-design>
    <pit-construct v-else-if="menuId==='1789220813020917762'" :constructlist="constructlist"></pit-construct>
  </view>
</template>

<script>
  import { apiBuildNewsTrendsEntityPage } from "@/api/build/newstrendsentity.js"
  import { apiBuildNotice } from "@/api/build/notice.js"
  import { apiBuildConstructionLogPage } from "@/api/build/constructionlog.js"
  import { apiQsSafeClassMeetingPage } from "@/api/qs/safeclassmeeting.js"
  import { apiQualityCheckingGetCheckingList } from '@/api/app/qualitychecking.js'
  import { apiBuildSupervisionDiaryPage } from '@/api/build/supervisiondiary.js'
  import { apiBuildSupervisionlogPage } from '@/api/build/supervisionlog.js'
  import { apiBuildSupervisionRecordPage } from '@/api/build/supervisionvisitationrecord.js'
  import { apiBuildSupervisorsitePage } from '@/api/build/supervisorsite.js'
  import { apiBuildProjectlogPage } from '@/api/build/projectmanagementlog.js'
  import { apiBuilddesignPage } from '@/api/build/designgenerationdiary.js'
  import { apiBuildConstructionPage } from '@/api/build/constructiondaily.js'
  export default{
    data(){
      return{
        menuId: "",
        videolist:['施工音像资料','监理音像资料','法人音像资料'],
        checklist:['法人检查通知','法人确认通知','日常检查'],
        safetylist:[
          {title:'监理检查',img:'/static/home/taskList/supervisor.png'},
          {title:'施工自检',img:'/static/home/taskList/shigongguanli.png'},
          {title:'日常巡视检查',img:'/static/home/workbench/quality_testing_empty.png'},
          {title:'全员监督检查',img:'/static/home/workbench/quality_testing_empty.png'}
        ],
        qualitychecklist:['监理检查','施工自检'],
        newslist:[],
        noticelist:[],
        buildlist:[],
        meetlist:[],
        supervisiondiarylist:[],
        supervisionloglist:[],
        supervisionrecordlist:[],
        supervisorsitelist:[],
        projectloglist:[],
        designlist:[],
        constructlist:[]
      }
    },
    onLoad(options) {
      if (options.id) {
        this.menuId = options.id;
      }
      if (options.title) {
        this.title = decodeURIComponent(options.title);
      }
      this.init()
    },
    methods:{
      init(){
        apiBuildNewsTrendsEntityPage().then(res=>{
          if(res.code==="00000"){
            this.newslist=res.data.list;
          } else{
            uni.showToast({
              title:'数据获取失败',
              icon:'none'
            });
          }
        });
        apiBuildNotice({ projectId:uni.getStorageSync("projectId")}).then(res=>{
          if (res.code === "00000") {
            this.noticelist = res.data.list.map(item => {
              let categoryText = "";
              if (item.category === "notice") {
                categoryText = "通知";
              } else if (item.category === "announcement") {
                categoryText = "公告";
              }
              return {
                ...item,
                category: categoryText
              };
            });
          }
        });
        apiBuildConstructionLogPage({ projectId:uni.getStorageSync("projectId")}).then(res=>{
          if (res.code === "00000") {
            this.buildlist = res.data.list.map(item => {
              let approvalStatusText = "";
              if (item.approvalStatus === "approval") {
                approvalStatusText = "等待审核";
              } else if (item.approvalStatus === "reject") {
                approvalStatusText = "审核驳回";
              } else if (item.approvalStatus === "end") {
                approvalStatusText = "流程结束";
              } else if (item.approvalStatus === "draft") {
                approvalStatusText = "等待提交"
              }
              return {
                ...item,
                approvalStatus: approvalStatusText
              };
            });
          }
        });
        apiQsSafeClassMeetingPage().then(res=>{
          if(res.code==="00000"){
            this.meetlist=res.data.list;
          } else {
            uni.showToast({
              title: '数据调取失败',
              icon: 'none'
            });
          }
        });
        apiBuildSupervisionDiaryPage({ projectId:uni.getStorageSync("projectId")}).then(res=>{
          if (res.code === "00000") {
            this.supervisiondiarylist = res.data.list.map(item => {
              let approvalStatusText = "";
              if (item.approvalStatus === "approval") {
                approvalStatusText = "等待审核";
              } else if (item.approvalStatus === "reject") {
                approvalStatusText = "审核驳回";
              } else if (item.approvalStatus === "end") {
                approvalStatusText = "流程结束";
              } else if (item.approvalStatus === "draft") {
                approvalStatusText = "等待提交"
              }
              return {
                ...item,
                approvalStatus: approvalStatusText
              };
            });
          }
        });
        apiBuildSupervisionlogPage({ projectId:uni.getStorageSync("projectId")}).then(res=>{
          if (res.code === "00000") {
            this.supervisionloglist = res.data.list.map(item => {
              let approvalStatusText = "";
              if (item.approvalStatus === "approval") {
                approvalStatusText = "等待审核";
              } else if (item.approvalStatus === "reject") {
                approvalStatusText = "审核驳回";
              } else if (item.approvalStatus === "end") {
                approvalStatusText = "流程结束";
              } else if (item.approvalStatus === "draft") {
                approvalStatusText = "等待提交"
              }
              return {
                ...item,
                approvalStatus: approvalStatusText
              };
            });
          }
        });
        apiBuildSupervisionRecordPage({ projectId:uni.getStorageSync("projectId")}).then(res=>{
          if (res.code === "00000") {
            this.supervisionrecordlist = res.data.list.map(item => {
              let approvalStatusText = "";
              if (item.approvalStatus === "approval") {
                approvalStatusText = "等待审核";
              } else if (item.approvalStatus === "reject") {
                approvalStatusText = "审核驳回";
              } else if (item.approvalStatus === "end") {
                approvalStatusText = "流程结束";
              } else if (item.approvalStatus === "draft") {
                approvalStatusText = "等待提交"
              }
              return {
                ...item,
                approvalStatus: approvalStatusText
              };
            });
          }
        });
        apiBuildSupervisorsitePage(
        {projectId:uni.getStorageSync("projectId"),
        constructionBid: "1704753634062962688"}
        ).then(res=>{
          if (res.code === "00000") {
            this.supervisorsitelist = res.data.list.map(item => {
              let approvalStatusText = "";
              if (item.approvalStatus === "approval") {
                approvalStatusText = "等待审核";
              } else if (item.approvalStatus === "reject") {
                approvalStatusText = "审核驳回";
              } else if (item.approvalStatus === "end") {
                approvalStatusText = "流程结束";
              } else if (item.approvalStatus === "draft") {
                approvalStatusText = "等待提交"
              }
              return {
                ...item,
                approvalStatus: approvalStatusText
              };
            });
          }
        });
        apiBuildProjectlogPage({projectId:uni.getStorageSync("projectId")}).then(res=>{
          if (res.code === "00000") {
            this.projectloglist = res.data.list.map(item => {
              let approvalStatusText = "";
              if (item.approvalStatus === "approval") {
                approvalStatusText = "等待审核";
              } else if (item.approvalStatus === "reject") {
                approvalStatusText = "审核驳回";
              } else if (item.approvalStatus === "end") {
                approvalStatusText = "流程结束";
              } else if (item.approvalStatus === "draft") {
                approvalStatusText = "等待提交"
              }
              return {
                ...item,
                approvalStatus: approvalStatusText
              };
            });
          }
        });
        apiBuilddesignPage({ projectId:uni.getStorageSync("projectId")}).then(res=>{
          if (res.code === "00000") {
            this.designlist = res.data.list.map(item => {
              let approvalStatusText = "";
              if (item.approvalStatus === "approval") {
                approvalStatusText = "等待审核";
              } else if (item.approvalStatus === "reject") {
                approvalStatusText = "审核驳回";
              } else if (item.approvalStatus === "end") {
                approvalStatusText = "流程结束";
              } else if (item.approvalStatus === "draft") {
                approvalStatusText = "等待提交"
              }
              return {
                ...item,
                approvalStatus: approvalStatusText
              };
            });
          }
        });
        apiBuildConstructionPage({ projectId:uni.getStorageSync("projectId")}).then(res=>{
          if (res.code === "00000") {
            this.constructlist = res.data.list.map(item => {
              let approvalStatusText = "";
              if (item.approvalStatus === "approval") {
                approvalStatusText = "等待审核";
              } else if (item.approvalStatus === "reject") {
                approvalStatusText = "审核驳回";
              } else if (item.approvalStatus === "end") {
                approvalStatusText = "流程结束";
              } else if (item.approvalStatus === "draft") {
                approvalStatusText = "等待提交"
              }
              return {
                ...item,
                approvalStatus: approvalStatusText
              };
            });
          }
        });
      },
      goback(){
        uni.navigateBack();
      },
    }
  }
</script>

<style lang="scss" scoped>
  .workbenchChild{
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background-color: rgb(240, 245, 252);
    .video,
    .check,
    .safety,
    .qualitycheck{
      flex: 1;
      padding: 10px 15px;
      .list-item{
        margin-bottom: 10px;
        display: flex;
        align-items: center;
        padding: 15px;
        border-radius: 10px;
        background-color: white;
        .list-item-img{
          width: 50px;
          height: 50px;
          margin-right: 10px;
        }
        .list-item-text{
          font-weight: 400;
        }
      }
    }
  }
</style>
